package com.jbp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jbp.dao.UserPropertyDao;
import com.jbp.model.UserProperty;
import org.springframework.stereotype.Service;

/**
 * 用户属性(UserProperty)表服务实现类
 * @author cc
 * @since 2021-12-06 20:08:06
 */
@Service
public class UserPropertyServiceImpl extends ServiceImpl<UserPropertyDao, UserProperty> implements IService<UserProperty> {
    public int getMaxGift(int userId) {
        UserProperty userProperty = getByUserId(userId);
        return userProperty==null ? 0 : Math.max(userProperty.getMaxLuck(), 6000);
    }

    public UserProperty getByUserId(int userId) {
        QueryWrapper<UserProperty> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return getOne(queryWrapper);
    }
}